# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Timothy Redaelli <timothy.redaelli@gmail.com>
# Contributor: Andy Weidenbaum <archbaum@gmail.com>
# Contributor: Kevin Azzam <arch@kevin.azz.am>

pkgname=python-hidapi
_pipname=hidapi
pkgver=0.14.0
# _pkgver=${pkgver%.*}.post${pkgver##*.}
_pkgver="$pkgver"
pkgrel=1
arch=('loong64' 'x86_64')
pkgdesc="A Cython interface to the hidapi from signal11/hidapi"
url="https://github.com/trezor/cython-hidapi"
depends=('python' 'hidapi')
makedepends=('cython' 'python-setuptools' 'udev')
license=('custom')
source=("https://pypi.org/packages/source/${_pipname:0:1}/$_pipname/$_pipname-$_pkgver.tar.gz")
sha512sums=('228fac22621e36a3108cefd418937a7ed0153e334e19999e947aad341a753d614877cd3f7add90d78037ebe9c7b3f6cbc42973a8e680188da14928311d317b17')

build() {
  cd "$_pipname-$_pkgver"

  python setup.py build \
        --without-libusb --with-system-hidapi
}

check() {
  cd "$_pipname-$_pkgver"

  local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
  #PYTHONPATH="$PWD/build/lib.linux-$CARCH-${python_version}" python tests.py
}

package_python-hidapi() {
  cd "$_pipname-$_pkgver"

  python setup.py install --root="$pkgdir" --optimize=1 --skip-build \
        --without-libusb --with-system-hidapi

  install -Dm 755 LICENSE.txt "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.txt
  install -Dm 755 LICENSE-bsd.txt "$pkgdir"/usr/share/licenses/$pkgname/LICENSE-bsd.txt
  install -Dm 755 LICENSE-gpl3.txt "$pkgdir"/usr/share/licenses/$pkgname/LICENSE-gpl3.txt
  install -Dm 755 LICENSE-orig.txt "$pkgdir"/usr/share/licenses/$pkgname/LICENSE-orig.txt
}
